package com.server.questionbank.snframe.mapper.Course.Member;

import com.server.questionbank.snframe.domain.Course.Member.UserRegistCus;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MemberMapper {
    // 加入课程
    @Insert("INSERT INTO user_regist_cus " +
            "(course_id, user_id, group_id, user_nick_name, permission) " +
            "VALUES (#{courseId}, #{userId}, #{groupId}, #{userNickName}, #{permission})")
    public Integer joinCourse(
            @Param("courseId") Long courseId,
            @Param("userId") Long userId,
            @Param("groupId") Long groupId,
            @Param("userNickName") String userNickName,
            @Param("role") String role,
            @Param("permission") Integer permission
    );

    // 获取课程成员列表
    @Select("SELECT * FROM user_regist_cus WHERE course_id = #{courseId}")
    public List<UserRegistCus> getCourseMemberList(Long courseId);

    // 获取课程成员列表
    @Select("SELECT * FROM user_regist_cus WHERE course_id = #{courseId} AND group_id = #{groupId}")
    public List<UserRegistCus> getCourseMemberListByGroupId(Long courseId, Long groupId);

    // 获取课程成员
    @Select("SELECT * FROM user_regist_cus WHERE course_id = #{courseId} AND user_id = #{userId}")
    public UserRegistCus getCourseMember(Long courseId, Long userId);
}
